package chapter4.collection_injection;

import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import javax.annotation.Resource;

import org.springframework.context.support.GenericXmlApplicationContext;
import org.springframework.stereotype.Service;

@Service("injectCollection")
public class CollectionInjection {
	@Resource(name = "maps")
	private Map<String, Object> maps;
	@Resource(name = "props")
	private Properties props;
	@Resource(name = "sets")
	private Set<Object> sets;
	@Resource(name = "list")
	private List<Object> list;

	public Map<String, Object> getMaps() {
		return maps;
	}

	public void setMaps(Map<String, Object> maps) {
		this.maps = maps;
	}

	public Properties getProps() {
		return props;
	}

	public void setProps(Properties props) {
		this.props = props;
	}

	public Set<Object> getSets() {
		return sets;
	}

	public void setSets(Set<Object> sets) {
		this.sets = sets;
	}

	public List<Object> getList() {
		return list;
	}

	public void setList(List<Object> list) {
		this.list = list;
	}

	public void display() {
		// display map
		System.out.println("Display content Map :");
		for (Map.Entry<String, Object> entry : maps.entrySet()) {
			System.out.println("\t Key : " + entry.getKey() + " - Value :"
					+ entry.getValue());
		}
		// Display properties
		System.out.println("Display content Properties : ");
		for (Map.Entry<Object, Object> entry : props.entrySet()) {
			System.out.println("\t Key : " + entry.getKey() + " - Value :"
					+ entry.getValue());
		}
		// Display content Set
		System.out.println("Display content Set :");
		for (Object object : sets) {
			System.out.println("\t Value :" + object);
		}
		System.out.println("Display content List :");
		for (Object object : list) {
			System.out.println("\t Value : " + object);
		}
	}

	public static void main(String[] args) {
		GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
		ctx.load("classpath:chapter4/collection_injection/app-context-xml.xml");
		ctx.refresh();

		CollectionInjection injection = (CollectionInjection) ctx
				.getBean("injectionCollection");
		injection.display();

		GenericXmlApplicationContext ctxa = new GenericXmlApplicationContext();
		ctxa.load("classpath:chapter4/collection_injection/app-context-annotation.xml");
		ctxa.refresh();

		CollectionInjection injection2 = (CollectionInjection) ctxa.getBean(
				"injectCollection", CollectionInjection.class);
		System.out.println("***********Annomation**************");
		injection2.display();
	}
}
